#region Copyright RenGuiYou. All rights reserved.
//=====================================================
// NeatlyFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================
#endregion

using System.Collections.Generic;
using System.Diagnostics;
using Neatly;
using Pandora.Console;
using UnityEngine;

namespace Pandora.Console
{
    public class LoadWindowBase : ScrollWindowBase
    {
        public enum AssetType
        {
            Bundle,
            Asset
        }

        protected AssetType m_Type;
        private Dictionary<string, Stopwatch> m_WatchDic;
        protected string topHint;

        protected override void OnDrawScrollableWindow()
        {
            GUILayout.Label(topHint);
            GUILayout.BeginVertical("box");
            {
                if (GUILayout.Button("刷新"))
                {
                    TakeSample();
                }
                GUILayout.Space(10);
                if (m_WatchDic != null && m_WatchDic.Count > 0)
                {
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label("<b>名字</b>");
                        GUILayout.Label("<b>加载耗时</b>", GUILayout.Width(240));
                    }
                    GUILayout.EndHorizontal();
                    foreach (var watch in m_WatchDic)
                    {
                        GUILayout.BeginHorizontal();
                        {
                            GUILayout.Label(watch.Key);
                            GUILayout.Label(watch.Value.ElapsedMilliseconds.ToString(), GUILayout.Width(240));
                        }
                        GUILayout.EndHorizontal();
                    }
                }
            }
            GUILayout.EndVertical();
        }

        private void TakeSample()
        {
            switch (m_Type)
            {
                case AssetType.Bundle:
                    m_WatchDic = Developer.LoadBundleDic;
                    break;
                case AssetType.Asset:
                    m_WatchDic = Developer.LoadAssetDic;
                    break;
            }
        }
    }
}